package com.difsonapps.android.marker.dialogs;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.Request.Method;
import com.difsonapps.android.marker.AppConstant;
import com.difsonapps.android.marker.CustomRequest;
import com.difsonapps.android.marker.IRefresher;
import com.difsonapps.android.marker.R;
import com.difsonapps.android.marker.app.AppController;
import com.difsonapps.android.marker.beans.Album;
import com.difsonapps.android.marker.beans.Photo;
import com.difsonapps.android.marker.beans.PhotoUpload;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;


public class DaoMenuActionsDialog extends Dialog{
	public static final int ACTION_EDIT = 1;
	public static final int ACTION_VIEW = 2;
	public static final int ACTION_DELETE = 3;
	public static final int ACTION_OPEN = 4;
	Activity activity;
	IRefresher<Integer> refresher;
	
	
	Button edit_menu;
	Button view_menu;
	Button delete_menu;
	Button open_menu;
	
	public DaoMenuActionsDialog(Activity activity,IRefresher<Integer> refresher, Map<String, Object> config) {
		super(activity);
		this.activity = activity;
		setTitle(R.string.menu);
		this.refresher = refresher;
		
		setContentView(R.layout.dialog_dao_menu_actions);
		edit_menu = (Button)findViewById(R.id.edit_menu);
		view_menu = (Button)findViewById(R.id.view_menu);
		delete_menu = (Button)findViewById(R.id.delete_menu);
		open_menu = (Button)findViewById(R.id.open_menu);
		//TODO use the config to show or hide some menus items
		
		edit_menu.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				execute(ACTION_EDIT);
			}
		});
		view_menu.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				execute(ACTION_VIEW);
			}
		});
		delete_menu.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				execute(ACTION_DELETE);
			}
		});
		open_menu.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				execute(ACTION_OPEN);
			}
		});
		findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				cancelAction();
			}
		});
	}
	
	private void execute(int menu){
		if(refresher!=null) {
			refresher.refresh(menu);
			dismiss();
		}
	}
	
	private void cancelAction(){
		dismiss();
	}

	private void toast(String text){
		Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
	}

}
